/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cassys.data.hibernate;

import cassys.data.AssessmentGroupDAO;
import cassys.domain.assessment.AssessmentGroup;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author Thurein
 */
public class AssessmentGroupHibernateDAO extends GenericHibernateDAO<AssessmentGroup, Long> implements AssessmentGroupDAO {

    public List<AssessmentGroup> getAssessmentGroup(long assessmentId){
        List<AssessmentGroup> result = new ArrayList<AssessmentGroup>();
        Criteria crit = getSession().createCriteria(AssessmentGroup.class, "ag");
        crit.createAlias("assessment", "a");
        crit.createAlias("members", "m");
        crit.add(Restrictions.eq("a.assessmentId", assessmentId));
        crit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        result = crit.list(); 
        return result;
    }

    public AssessmentGroup getAssessmentGroupById(long assessmentGroupId){
        Criteria crit = getSession().createCriteria(AssessmentGroup.class, "ag");
        crit.createAlias("assessment", "a");
        crit.createAlias("members", "m");
        crit.add(Restrictions.eq("ag.assessmentGroupId", assessmentGroupId));
        crit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        return (AssessmentGroup)crit.list().get(0);
    }
}
